<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fm" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>住院医生站</title>
</head>
<body>
<style type="text/css">
.ljw-span{
    display: inline-block;
    width: 100%;;
    height: 20px;
}
.dep-span{
	float: right;
	width: 100px;
	text-align: center;
}
.person-box-doctor{
	box-shadow: 0px 0px 2px 2px #ddd;
	margin: 10px 15px;
	border: 1px solid #A8A8A8;
	border-radius:5px;
	width:240px;
	display: inline-block;
	position:relative;
	cursor: pointer;
}  
.person-img{
	box-shadow: 0px 2px #ddd;
	border: 3px solid white;
	width: 60px;
	float:left;
}
.person-nameBox{
	float:left;
	width:140px;
	padding-left: 15px;
}
.nameSpan{
	font-weight: bold;
	font-size: 18px;
}
.timeBox{
    padding-left: 10px;
    padding-bottom: 4px;
    font-size: 13px;
}
.imgBox{
	overflow: auto;
	padding: 8px 8px 2px 8px;
}
.stateBox{
	background: #E0ECF4;
	text-align: center;
	line-height:30px;
}
.person-doctorWin i{
    border-bottom: 1px solid #aaa;
    display: inline-block;
    padding: 0 30px;
    text-align: center;
}
.delRow_{
	color: rgb(234, 98, 18);
	cursor: pointer;
}
.person-doctorWin .text-css{
	border: 0px;
    border-bottom: 1px solid #aaa;
    background-color: rgba(0,0,0,0);
    text-align: center;
    width: 80px;
    height: 24px;
    outline: none;
    font-style: italic;
    color: black;
    
}
#opsBox .text-css{
	border: 0px;
    background-color: rgba(0,0,0,0);
    text-align: center;
    width: 80px;
    height: 24px;
    outline: none;
    font-style: italic;
    color:black;
    border-bottom: 1px solid #ccc;
}
.adviceFie .a-Css{
    display: inline-block;
    border: 1px solid gray;
    background: #dee;
    padding: 2px 10px;
    border-radius: 5px;
    text-decoration: none;
    cursor: pointer;
}
</style>
<script type="text/javascript">
$(function(){

	var did = ${user.departmentsPx.departmentsId };
	
	//卡片悬浮事件
	$(".person-box-doctor").hover(
		function(){
			$(this).stop().css("box-shadow","0px 0px 4px 4px #ddd");
		},
		function(){
			$(this).stop().css("box-shadow","0px 0px 2px 2px #ddd");
		}
	);
	
	//卡片弹窗
	$(".person-box-doctor").click(function(){
		$("#balanceId").tooltip("hide");
		$(".person-doctorWin").window("open");//弹窗
		$('#caseBtn').linkbutton('disable');//确认按钮禁用
		$('#adviceTab').tabs('select','患者信息');//默认选中第一个选项卡
		//清空之前的数据
		$("#adviceTable").datagrid("loadData", { total: 0, rows: [] });
		$("#daysText").textbox('setValue','');
		$("#entrustText").textbox('setValue','');
		var hid = $(this).attr('id');
		$.post('ljw-patient-data',
			{"hid":hid},
			function(data){
				$("#adviceTab input[name='patient_hid']").val(hid);
				$("#adviceTab input[name='bedText']").val(data[0].bed_number);
				$("#adviceTab input[name='nameText']").val(data[0].patient_name);
				$("#adviceTab input[name='sexText']").val(data[0].patient_sex);
				$("#adviceTab input[name='ageText']").val(data[0].patient_age);
				$("#adviceTab input[name='phoneText']").val(data[0].mzcard_phone);
				$("#adviceTab input[name='addressText']").val(data[0].home_address);
				$("#adviceTab input[name='cidText']").val(data[0].card_cid);
				$("#adviceTab input[name='caseComplaint']").val(data[0].case_complaint);
				$("#adviceTab input[name='caseDisease']").val(data[0].case_disease);
				$("#adviceTab input[name='caseAllergy']").val(data[0].case_allergy);
				$("#adviceTab input[name='caseComplaint']").attr("disabled",true);
				$("#adviceTab input[name='caseDisease']").attr("disabled",true);
				$("#adviceTab input[name='caseAllergy']").attr("disabled",true);
				$("#adviceTab input[name='balanceText']").val(data[0].balance.toFixed(2));
			}
		);
	});
	
	//医嘱表格初始化
	$("#adviceTable").datagrid({
		columns:[[ 
			{field:'drug_name',title:'项 目 名 称',width:220,halign:'center'},
			{field:'type',title:'类 型',width:80,align:'center'},
			{field:'drug_selling_price',title:'单 价',width:90,halign:'center'},
			{field:'drug_specifications',title:'单 位',width:50,halign:'center'},
			{field:'advice_Details_number',title:'数  量',width:60,halign:'center',
				editor:{
			       type:'numberspinner',
			       options:{min:1,required: true}
			    }
			},
			{field:'advice_Details_hz',title:'频 率',width:140,halign:'center',
				editor:{
			       type:'validatebox',
			       options:{required: true,validType:"isNull"}
				} 		
			},
			{field:'handle',title:'操 作',width:80,align:'center'} 
		]]
	}); 
	
	$(".big_tabs").tabs({//选项卡切换时就刷新
		onSelect:function(title){
			if(title=="医嘱管理"){
				$("#adTable").datagrid({
					url:'ljw-advice-find'
				});				
			}
		}
	}); 
	
	//文本框验证
	$.extend($.fn.validatebox.defaults.rules, {    
	   isNull: {
			validator: function(value, param){ 
				if($.trim(value)==""){
					return false;
				}
           		return true;
            }, 
		    message: '不能为空白字符' 
	   } 
	});
	
	//选择录入按钮
	$("#inBtn").click(function(){
		$(".inWin").window("open");
		$('.advTabs').tabs('select','药品');//默认选中第一个选项卡
		initDrugTable('');//初始化表格数据
	});
	
	//药品搜索框
	$("#drugText").searchbox({
		searcher:function(value){
			initDrugTable(value);
		}
	});
	
	//药品的添加按钮
	$(".addDrug").click(function(){
		var rows1 =$("#adviceTable").datagrid("getRows");
		var rows2 = $("#drugTable").datagrid("getSelections");
		addItem(rows1,rows2);
	});
	
	//体检的添加按钮
	$(".addEx").click(function(){
		var rows1 =$("#adviceTable").datagrid("getRows");
		var rows2 = $("#exItemTable").datagrid("getSelections");
		addItem(rows1,rows2);
	});
	
	//返回按钮
	$(".backBtn").click(function(){
		$(".inWin").window("close");
	});
	
	//医嘱表格
	$("#adviceTable").datagrid({
		onClickRow:function(index){//设置不可选中
			$(this).datagrid('unselectRow',index);
		}
	});
	
	//选项卡点击时刷新表格数据
	$(".advTabs").tabs({
		onSelect:function(title){
			if(title=="检查"){
				$('#exItemTable').datagrid({
					url:"ljw-examine", 
					columns:[[
		    			{field:'examine_item_id',title:'项 目 编 号',width:100,halign:'center'},
		    			{field:'examine_item_name',title:'项 目 名 称',width:200,halign:'center'},
		    			{field:'examine_item_price',title:'单 价',width:100,halign:'center',
		    				formatter:function(value,row,index){
		    					return "￥" + value.toFixed(2);
							}	
		    			}
					]]
				}); 
			}
		}
	}); 
	
	//提交医嘱按钮
	$("#putBtn").click(function(){
		var hid = $("input[name='patient_hid']").val();
		var rows = $("#adviceTable").datagrid("getRows");
		if(rows.length<1)return;
		$("<form method='post' id='adviceForm'>").appendTo("body").form({
			url:'ljw-advice-add',
			onSubmit:function(param){
				var opin = $("#adviceForm").form('enableValidation').form('validate');
				//住院id
				param["advice.hospital.hospitalId"] = $("input[name='patient_hid']").val();
				console.log($("input[name='patient_hid']").val());
				//医嘱类型
				param['advice.adviceDays'] = $("input[name='adviceType']:checked").val();
				//医生嘱咐
				param['advice.adviceEntrust'] = $("#entrustText").textbox('getValue');
				//总费用
				var total = 0;
				for (var i = 0; i < rows.length; i++) {
					$("#adviceTable").datagrid('endEdit',i);//关闭编辑器
					var row = rows[i];
					param["details["+i+"].drugsYk.drugId"] = row["drug_id"];
					param["details["+i+"].advice_Details_number"]= row["advice_Details_number"];
					param["details["+i+"].advice_Details_hz"]= row["advice_Details_hz"];
					param["details["+i+"].executeType"] = row["type"];
					if(row["type"]=="药品" && $.trim(row["advice_Details_hz"])==""){
						for (var i = 0; i < rows.length; i++) {
							if(rows[i]["type"]=="药品"){
								$("#adviceTable").datagrid('beginEdit',i);//开启编辑器
							}
						}
						return false;
					}
					var p = rows[i]["drug_selling_price"];
					var n = rows[i]["advice_Details_number"];
					var price = p.substr(1); 
					total = total + parseInt(price)*parseInt(n);
				}
				$('#balanceId').tooltip({//提示框
				    position: 'right',
				    content: '<span style="color:red">总费用￥'+total.toFixed(2)+'，余额不足!</span>' 
				});
				console.log(total);
				var balanceText = $("#adviceTab input[name='balanceText']").val();
				if(total>balanceText){
					for (var i = 0; i < rows.length; i++) {
						if(rows[i]["type"]=="药品"){
							$("#adviceTable").datagrid('beginEdit',i);//开启编辑器
						}
						var obj = $(".delRow_");
						$(obj[i]).attr("onclick","removeRow("+i+")");
					} 
					$("#balanceId").tooltip("show");
					return false;
				}else{
					$("#balanceId").tooltip("hide");
				}
			},
			success:function(data){
				//清空表格数据
				$("#adviceTable").datagrid("loadData", { total: 0, rows: [] });
				$("#daysText").textbox('setValue','');
				$("#entrustText").textbox('setValue','');
			}
		}).submit();
		$("#adviceForm").form('clear');
	});
	
	//选择患者的下拉表格
	$('#opsSear').combogrid({    
	    panelWidth:435,
	    idField: 'hospital_id',  
        textField:'patient_name', 
	    url:'ljw-leave-patient',    
	    columns:[[    
	        {field:'hospital_id',title:'住 院 号',width:80,halign:'center'}, 
	        {field:'patient_name',title:'姓 名',width:100,halign:'center'},    
	        {field:'patient_sex',title:'性 别',width:60,halign:'center'},    
	        {field:'patient_age',title:'年 龄',width:60,halign:'center'},    
	        {field:'case_disease',title:'诊 断 病 症',width:120,halign:'center'}    
	    ]]    
	});  

	$(".big_tabs").tabs({//选项卡切换时就刷新
		onSelect:function(title){
			if(title=="手术安排"){
				$('#opsSear').combogrid({   
					url:'ljw-leave-patient',    
				});				
			}
		}
	});
	
	//选择手术的下拉表格
	$('#selectOps').combogrid({    
	    panelWidth:345,
	    idField: 'operation_id',  
        textField:'operation_name', 
	    url:'ljw-ops?did='+1,
	    columns:[[         
	        {field:'departments_name',title:'科 室',width:100,halign:'center'},
	        {field:'opertation_money',title:'单 价',width:90,halign:'center',
	        	formatter:function(value,row,index){
					return "￥" + value.toFixed(2);
				}	
	        },  
	        {field:'operation_name',title:'手 术 名 称',width:140,halign:'center'}  
	    ]]    
	});  
	
	//医嘱管理表格
	$("#adTable").datagrid({
		url:'ljw-advice-find',
		fitColumns:true,
		pagination:true,
		singleSelect:true,
		pageSize:10,
	    pageList:[10,20],
	    columns:[[         
	        {field:'advice_id',hidden:true},
	        {field:'hospital_id',title:'住 院 号',width:100,halign:'center'},
	        {field:'patient_name',title:'患 者 姓 名',width:120,halign:'center'},
	        {field:'patient_sex',title:'患 者 性 别',width:80,halign:'center'},
	        {field:'advice_doctor',title:'开 嘱 医 生',width:120,halign:'center'},  
	        {field:'advice_time',title:'开 嘱 时 间',width:150,halign:'center',
	        	formatter:function(value,row,index){
					var time = new Date(value).toJSON();
					var date = new Date(+new Date(time)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'') ;
					return date;
				}	
	        },
	        {field:'advice_entrust',title:'医 生嘱 咐',width:120,halign:'center'}, 
	        {field:'advice_days',title:'医 嘱 类 型',width:100,align:'center',
	        	formatter:function(value,row,index){
	        		if(value=="1"){
						return "临时";
	        		}
					return "长期";
				}	
	        },
	        {field:'advice_state',title:'执 行 状 态',width:120,align:'center'}
	    ]] 
	});
	
	//医嘱管理搜索框
	$("#hidText2").searchbox({
		searcher:function(value){
			$("#adTable").datagrid({
				url:"ljw-advice-find?str="+value,
			});
		}
	});
	
	//详情按钮
	$("#adDetailsBtn").click(function(){
		var row = $("#adTable").datagrid("getSelected");
		if(row==null){
			return;
		}
		$(".adDetailWin").window("open");
		$("#adDetailTable").datagrid({
			fitColumns:true,
			url:"ljw-adDetils?aid="+row.advice_id,
			columns:[[         
			 	{field:'drug_name',title:'药 品 名 称',width:150,halign:'center'},
		        {field:'drug_types_name',title:'药 品 类 别',width:100,halign:'center'},
		        {field:'Advice_Details_number',title:'数 量',width:60,halign:'center'},
		        {field:'drug_specifications',title:'单 位',width:60,halign:'center'},  
		        {field:'drug_selling_price',title:'单 价',width:80,halign:'center',
		        	formatter:function(value,row,index){
						return "￥" + value.toFixed(2);
					}	
		        },  
		        {field:'Advice_Details_hz',title:'频 率',width:120,halign:'center'}
			]]
		 });
	});
	
	//停嘱按钮
	$("#endBtn").click(function(){
		var row = $("#adTable").datagrid("getSelected");
		if(row==null){
			return;
		}
		if(row.advice_state!="已停嘱"){
			$.messager.confirm(
				'确认框', '确定停止这条医嘱',
				function(r){
					if (r){
						$.post(
							"ljw-updateAdvice",
							{"aid":row.advice_id},
							function(data){
								 $("#adTable").datagrid("reload");
								 $.messager.show({
									title:'提 示',
									msg:'已 停 嘱',
									height:200,
									timeout:800,
									showType:'slide'
								 });
							}
						);
					}
				}
			);
		}else{
			$.messager.show({
				title:'提 示',
				msg:'已 停 嘱',
				height:200,
				timeout:3000,
				showType:'slide'
			 });
		}
	});
	
	//手术确定按钮
	$("#okOps").click(function(){
		var hid = $("#opsSear").combogrid("getValue");//住院号
		var ops = $("#selectOps").combogrid("getValue");//手术项目
		var startTime = $("#startTime").datetimebox("getValue");
		var endTime = $("#endTime").timespinner("getValue");
		var nurseId = $("#setNurse").combobox("getValue");
		var row = $("#opsSear").combogrid("grid");
		var obj =  row.datagrid('getSelected');
		var theaterId = $("#setTheater").combobox("getValue");
		var diagnose = "";
		if(obj==null)return;
		if(obj.hasOwnProperty("case_disease")){
			diagnose = obj.case_disease;
		}
		var rows = $("#ops2-Table").datagrid("getRows");
		var opin = true;
		var s = new Date(startTime).getTime();//开始时间
		var e = new Date(startTime.substring(0,10)+" "+endTime).getTime();//结束时间
	   	var theater = $("#setTheater").combobox("getText");//手术室
		for (var i = 0; i < rows.length; i++) {//遍历表格时间作比对
			var row = rows[i];
		   	var result = row.operation_record_state;//手术结果
			var start = new Date(row.operation_record_start_time);
			var end = new Date(row.operation_record_start_time.substring(0,10)+" "+ row.operation_record_end_time);
		 	if(theater==row.theater_name){//判断同一科室下
		 		if(s>start.getTime() && s<end.getTime()){//开始时间判断
			 		opin = false;
					console.log(row.operation_record_start_time+"==开始有安排=="+row.operation_record_end_time);
			 	}
			 	if(e>start.getTime() && e<end.getTime()){//结束时间判断
			 		opin = false;
			 		console.log(row.operation_record_start_time+"==结束有安排=="+row.operation_record_end_time);
			 	} 
		 	}
		}
	   	//等于false则不能新增手术
		if(opin==false){
			$.messager.alert('提示','该手术室该时间段已安排手术','info');
			return;
		}
	   	//新增安排手术
		$("#opsForm").form({
			url:"ljw-ops-add?startTime="+startTime+"&endTime="+endTime
					+"&hospital.hospitalId="+hid+"&user1.userId="+nurseId
					+"&operation.operationId="+ops+"&operationRecordDiagnose="+diagnose+"&theater.theaterId="+theaterId,
			onSubmit:function(param){
				return $(this).form('enableValidation').form('validate');
			},
			success:function(data){
				if(data=="成功"){
					$.messager.alert('提示','登记成功','info');
					$("#ops2-Table").datagrid("reload");
					$("#opsForm").form("clear");
				}else{
					$.messager.alert('提示','该手术室该时间段已安排手术','info');
				}
			}
		}).submit();
	});
	
	//护士的下拉框初始化
	$("#setNurse").combobox({
		url:'cxsbhs?ksid='+did ,
		valueField:"user_id",
		textField:"user_name"
	});
	
	//手术室的下拉框初始化
	$("#setTheater").combobox({
		url:'ljw-theater',
		valueField:"theater_id",
		textField:"theater_name"
	});
	
	//手术安排记录的表格
	$("#ops2-Table").datagrid({
		url:'ljw-ops-find',
		fitColumns:true,
		columns:[[
			{field:'operation_record_id',hidden:true},
			{field:'hospital_id',title:'住 院 号',width:60,halign:'center'},
			{field:'patient_name',title:'患 者 姓 名',width:100,halign:'center'},
			{field:'patient_sex',title:'性 别',width:50,halign:'center'},
			{field:'patient_age',title:'年 龄',width:50,halign:'center'},
			{field:'operation_record_diagnose',title:'术 前 诊 断',width:120,halign:'center'},
			{field:'operation_name',title:'手 术 名 称',width:120,halign:'center'},
			{field:'operation_record_start_time',title:'开 始 时 间',width:150,align:'center',
				formatter:function(value,row,index){
					var time = new Date(value).toJSON();
					var date = new Date(+new Date(time)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'') ;
					return date;
				}	
			},
			{field:'operation_record_end_time',title:'结 束 时 间',width:120,align:'center'},
			{field:'theater_name',title:'手 术 室',width:100,align:'center'},
			{field:'operation_record_state',title:'手 术 结 果',width:140,halign:'center',
				editor:{
			       type:'text',
			       options:{required: true}
			    }	
			},
			{field:'handle',title:'操 作',width:120,align:'center',
				formatter:function(value,row,index){
					if($.trim(row.operation_record_state)==""){
						if (row.editing){
							var s = '<input type="button" style="cursor:pointer;background:#E4F1FB;color:#2779AA;border:none" onclick="saverow('+index+')" value="保存"/> ';
							var c = '<input type="button" style="cursor:pointer;background:#E4F1FB;color:#2779AA;border:none" onclick="cancelrow('+index+')" value="取消"/> ';
							return s+c;
						} else {
							var e = '<input type="button" style="cursor:pointer;background:#E4F1FB;color:#2779AA;border:none" onclick="editrow('+index+')" value="结果录入"/> ';
							var d = '<input type="button" style="cursor:pointer;background:#E4F1FB;color:#2779AA;border:none" onclick="deleterow('+index+')" value="撤销"/> ';
							if(new Date(row.operation_record_start_time)>new Date()){
								return e+d;
							}
							return e;
						} 
					}
				} 
			}
		]],
		onClickRow:function(index){//设置不可选中
			$(this).datagrid('unselectRow',index);
		},
		onBeforeEdit:function(index,row){
			$(this).datagrid('updateRow', {index:index,row:{editing:true}})
		},
		onAfterEdit:function(index,row){
			$(this).datagrid('updateRow', {index:index,row:{editing:false}})
		},
		onCancelEdit:function(index,row){
			$(this).datagrid('updateRow', {index:index,row:{editing:false}})
		}
	});
	
	
	//开始日期框设置之前日期不可选
	$('#startTime').datebox().datebox('calendar').calendar({
	    validator : function(date){
	        var now = new Date();
	        var d1 = new Date(now.getFullYear(),now.getMonth(),now.getDate());
	        return d1 <= date;
	    }
	}); 
	 
	//开始日期框选择时事件
	$('#startTime').datetimebox({
		onChange: function(newDate, oldDate){
			var startDate = new Date(newDate);
	        var s = startDate.getHours()+":"+(startDate.getMinutes())
	        $('#endTime').timespinner({    
	            min: s
	        });  
	    	//$("#endTime").timespinner("setValue",s);
	    }
	});

	//新增病历的保存按钮
	$("#caseBtn").click(function(){
		if ($(this).linkbutton('options').disabled == true) {
			return ;
		}
		var hid = $(".person-doctorWin input[name='patient_hid']").val();
		$("#caseForm").form({
			url:'ljw-case?hospital.hospitalId='+hid,
			onSubmit: function(){
				
		    },    
		    success:function(data){
		    	if(data=="fasle"){
			    	alert("失败--"+data);
		    	}
		    	$(".stateBox").text("住院中");
		    	$("input[name='caseComplaint']").attr("disabled",true).css({"background":"bottom","border":"0","border-bottom": "1px solid #bbb"});
				$("input[name='caseDisease']").attr("disabled",true).css({"background":"bottom","border":"0","border-bottom": "1px solid #bbb"});
				$("input[name='caseAllergy']").attr("disabled",true).css({"background":"bottom","border":"0","border-bottom": "1px solid #bbb"});
		    	$('#caseBtn').linkbutton('disable');
		    }    
		}).submit();
	}); 
	
	//编辑按钮
	$("#editBtn").click(function(){
		$("input[name='caseComplaint']").attr("disabled",false).css({"border": "1px solid #bbb"});
		$("input[name='caseDisease']").attr("disabled",false).css({"border": "1px solid #bbb"});
		$("input[name='caseAllergy']").attr("disabled",false).css({"border": "1px solid #bbb"});
		$("input[name='caseComplaint']").focus();
		$('#caseBtn').linkbutton('enable');
	});
	
	$('#balanceId').tooltip({//提示框
	    position: 'right',
	    showEvent: null 
	});
	
});

//开启编辑器
function editrow(index){
	$('#ops2-Table').datagrid('beginEdit', index);
}
//关闭编辑器
function cancelrow(index){//取消
	$('#ops2-Table').datagrid('cancelEdit', index);
}
function saverow(index){//保存事件
	$('#ops2-Table').datagrid('endEdit', index);
	var rows = $('#ops2-Table').datagrid("getRows");
	var row = rows[index];
	var result = row.operation_record_state;
	var rid = row.operation_record_id;
	console.log(result+"---"+rid);
	if(result==""||typeof(result)=='undefined'){
		return;
	}
	$.post(
		"ljw-ops-result",
		{"rid":rid,"result":result}	,
		function(data){
			//alert("成功");
		}
	);
}
function deleterow(index){//撤销
	var rows = $('#ops2-Table').datagrid("getRows");
	var row = rows[index];
	$.post("ljw-deleteOps",{"rid":row.operation_record_id},
		function(data){
			$("#ops2-Table").datagrid("deleteRow",index);
			$("#ops2-Table").datagrid("reload");
		}
	);
}

//添加到医嘱表格
function addItem(rows1,rows2){
	if(rows2.length==0){
		return;
	}
	//外循环
	$.each(rows2,function(key,value){
		console.log(key+"---"+value.drug_name);
		var opin = true;
		//内循环
		for (var i = 0; i < rows1.length; i++) {
			var row = rows1[i];
			if(value.drug_id == row.drug_id||value.examine_item_id == row.drug_id){
				opin = false;
			}
		}
		var eid = value.examine_item_id;
		var a = true;
		if(typeof(eid)=="undefined"){
			a = false;
		}
		if(opin){//如果为true表示不重复则新增行
			if(a){
				$("#adviceTable").datagrid('appendRow',{
					drug_id: value.examine_item_id,
					drug_name: value.examine_item_name,
					type: "检查",
					drug_specifications:"次",
					drug_selling_price:"￥"+value.examine_item_price.toFixed(2),
					advice_Details_number:1,
					handle:"<a class='delRow_' onclick=''>删除</a>"
				});
			}else{
				$("#adviceTable").datagrid('appendRow',{
					drug_id: value.drug_id ,
					drug_name: value.drug_name,
					type: "药品",
					drug_specifications: value.drug_specifications,
					drug_selling_price: "￥"+value.drug_selling_price.toFixed(2),
					advice_Details_number: 1,
					handle:"<a class='delRow_' onclick=''>删除</a>"
				});
			}
		}
	});
	//循环第一个表格，开启行内编辑器,并赋值新的索引行给删除事件
	for (var i = 0; i < rows1.length; i++) {
		if(rows1[i].type=="药品"){
			$("#adviceTable").datagrid("beginEdit", i);
		}
		var obj = $(".delRow_");
		$(obj[i]).attr("onclick","removeRow("+i+")");
	}
	$(".inWin").window("close");//关闭当前窗口
}

//删除行
function removeRow(index){
	$("#adviceTable").datagrid("deleteRow",index);
	//重新刷新删除事件的索引
	var rows1 =$("#adviceTable").datagrid("getRows");
	for (var i = 0; i < rows1.length; i++) {
		var obj = $(".delRow_");
		$(obj[i]).attr("onclick","removeRow("+i+")");
	}
}

//药品表格初始化数据
function initDrugTable(name){
	$("#drugTable").datagrid({
		url:'ljw-drug?name='+name,
		fitColumns:true,
		pagination:true,
		pageSize:8,
	    pageList:[8,16],
		columns:[[
			{field:'drug_checkbox',checkbox:true},
			{field:'drug_id',title:'编 号',width:100,halign:'center'},
			{field:'drug_name',title:'药 品 名 称',width:240,halign:'center'},
			{field:'drug_specifications',title:'单 位',width:80,halign:'center'},
			{field:'drug_selling_price',title:'价 格',width:100,halign:'center',
				formatter:function(value,row,index){
					return "￥" + value.toFixed(2);
				}
			}
		]]
	});
}
</script>
<div class="easyui-tabs big_tabs" style="width:100%;height:100%;user-select:none">
	<div title="患者列表"> 
		<!-- 患者列表弹出层  Start -->
		<div class="easyui-window person-doctorWin" title="患者信息" style="width:750px;height:500px;"
			data-options="modal:true,collapsible:false,minimizable:false,
			maximizable:false,closed:true,draggable:false,shadow:true,resizable:false" style="padding:20px 40px">
			<div id="adviceTab" class="easyui-tabs" fit="true" style="user-select:none">
				<div title="患者信息" style="background: #dee">
					<div style="margin: 0 auto;width: 600px; padding: 5px 20px; ">
						<p>
							<span style="display: inline-block;">
								住院号：<input name="patient_hid" class="text-css" disabled="disabled" style="width: 120px;padding: 0 15px;">
							</span>
							<span style="display: inline-block;margin-left: 30px;">
								床位：<input name="bedText" class="text-css" disabled="disabled" style="width: 50px;padding: 0 15px;">
							</span>
							<span style="display: inline-block;margin-left: 30px;">
								姓名：<input name="nameText" class="text-css" disabled="disabled" style="width: 100px;padding: 0 15px;">
									<input name="patient_hid" type="hidden" >
							</span>
						</p>
						<p>
							<span style="display: inline-block;">
								性别：<input name="sexText" class="text-css" disabled="disabled" style="width: 30px;padding: 0 15px;">
							</span>
							<span style="display: inline-block;margin-left: 30px;">
								年龄：<input name="ageText" class="text-css" style="width: 30px;padding: 0 15px;" disabled="disabled">
							</span>
							<span style="display: inline-block;margin-left: 30px;">
								身份证号：<input name="cidText" class="text-css" disabled="disabled" style="width: 200px;padding: 0 15px;">
							</span>
						</p>
						<p>
							<span style="display: inline-block;">
								联系电话：<input name="phoneText" class="text-css" disabled="disabled" style="width: 84px;padding: 0 15px;">
							</span>
							<span style="display: inline-block;margin-left: 30px;">
								家庭住址：<input name="addressText" class="text-css" disabled="disabled" style="width: 310px;">
							</span>
							
						</p>
					</div>
					<fieldset style="width: 600px; margin: 15px auto;
									border-radius: 5px;border: 2px solid #bbf;">
						<legend>病历信息</legend>
						<form method="post" id="caseForm">
							<p style="padding-left: 35px;">
								主诉症状：<input name="caseComplaint"  style="width:450px;
											height:28px;padding-left:5px;
											background: bottom;
    										border: 0; 
											border-bottom: 1px solid #bbb;">
							</p>
							<p style="padding-left: 35px;">
								诊断病症：<input name="caseDisease" style="width:450px;
											height:28px;padding-left:5px;
											background: bottom;
    										border: 0; 
											border-bottom: 1px solid #bbb;">
							</p>
							<p style="padding-left: 35px;">
								过敏药物：<input name="caseAllergy" style="width:450px;
											height:28px;padding-left:5px;
											background: bottom;
    										border: 0; 
											border-bottom: 1px solid #bbb;">
							</p>
							<a id="caseBtn" class="easyui-linkbutton" 
								style="padding:0 8px;float: right;margin-right: 40px;">保存</a>	
							<a id="editBtn" class="easyui-linkbutton" 
								style="padding:0 8px;float: right;margin-right: 35px;">编辑</a>	
							
						</form>
					</fieldset>
				</div>
				<div title="医嘱录入">
					<div style="background: #dee;">
						<div style="display: inline-block;border-bottom: 1px solid #ccc;padding: 5px 20px;width: 694px;;">
							<span style="display: inline-block;margin-left: 30px;">
								姓名：<input name="nameText" class="text-css" disabled="disabled" style="width: 120px;">
									<input name="patient_hid" type="hidden" >
							</span>
							<span style="display: inline-block;margin-left: 30px;">
								性别：<input name="sexText" class="text-css" disabled="disabled" style="width: 50px"> 
							</span>
							<span style="display: inline-block;margin-left: 30px;">
								年龄：<input name="ageText" class="text-css" style="width: 50px" disabled="disabled">
							</span>
							<span id="balanceId" style="display: inline-block;margin-left: 30px;">
								押金余额：<input  name="balanceText" class="text-css" style="width: 100px" disabled="disabled">
							</span> 
						</div>
						<div style="padding: 5px;display: inline-block;">
							<a id="putBtn" class="easyui-linkbutton" iconCls="icon-save" style="padding:0 5px;margin-left: 10px;">提交医嘱</a>	
							<a id="inBtn" class="easyui-linkbutton" iconCls="icon-add" style="padding:0 5px;margin-left: 10px;">选择录入</a>	
							<div style="display: inline-block;margin: 0 12px;border: 1px solid darkseagreen;border-radius: 3px;height: 24px;padding: 0 8px;padding-top: 3px;">
								<label style="display: inline-block;width: 82px;">
									<input value="1" checked="checked" name="adviceType" type="radio" style="float: left;margin-top: 4px;cursor: pointer;">临时医嘱
								</label>
								<label style="display: inline-block;width: 82px;">
									<input value="2" name="adviceType" type="radio" style="float: left;margin-top: 4px;cursor: pointer;">长期医嘱
								</label>
							</div>
							<input id="entrustText" class="easyui-textbox" data-options="label:'医生嘱咐：',labelAlign:'right'" style="width:260px;padding-left:5px;">
						</div>
					</div>
					<table id="adviceTable" class="easyui-datagrid" style="height:340px;">   
						 
					</table>
					<!-- 选择录入的弹出层 -->
					<div class="easyui-window inWin" title="选择录入" style="width:590px;height:440px;user-select:none;"
						data-options="modal:true,collapsible:false,minimizable:false,
						maximizable:false,closed:true,draggable:false,shadow:true,resizable:false">
						 <div class="easyui-tabs advTabs" fit="true">
						 	<div title="药品">
						 		<div style="background: #dee;padding: 5px;">
								 	<input id="drugText" class="easyui-searchbox" style="width:160px;height:28px;padding-left:5px;">
								 	<a class="easyui-linkbutton addDrug" style="padding:0 5px;margin-left: 50px;">添加</a>
								 	<a class="easyui-linkbutton backBtn" style="padding:0 5px;margin-left: 30px;">返回</a>	
								</div>
								<table id="drugTable" class="easyui-datagrid" style="height:325px;">   
						
								</table>
							</div>
						 	<div title="检查">
						 		<div style="background: #dee;padding: 5px;">
								 	<input class="easyui-searchbox" style="width:160px;height:28px;padding-left:5px;">
								 	<a class="easyui-linkbutton addEx" style="padding:0 5px;margin-left: 50px;">添加</a>
								 	<a class="easyui-linkbutton backBtn" style="padding:0 5px;margin-left: 30px;">返回</a>	
								 </div>
								 <table id="exItemTable" class="easyui-datagrid" style="height:325px;" 
					        		data-options="fitColumns:true,">   
								  	<thead>  
								        <tr>
								            <th data-options="field:'examine_item_id',width:100,halign:'center'">项 目 编 号</th>   
								            <th data-options="field:'examine_item_name',width:240,halign:'center'">项 目 名 称</th>  
								            <th data-options="field:'examine_item_price',width:100,halign:'center'">单 价</th>
								        </tr>   
								    </thead>  
								</table>
						 	</div>
						 </div>
					</div>
				</div>
			</div>
		</div>
		<!-- 患者列表弹出层  End -->
		
		<!-- 患者卡片  Start -->
		<div id="patientBox" style="width:1120px;margin: 15px auto;">
		<c:forEach items="${array }" var="p">
			<div class="person-box-doctor" onclick="" id="${p.hospital_id }">
				<div class="imgBox">
					<c:if test="${p.patient_sex == '女'}">
					<img class="person-img" src="/static/img/女士.png">
					</c:if>
					<c:if test="${p.patient_sex == '男'}">
					<img class="person-img" src="/static/img/男士.png">
					</c:if>
					<div class="person-nameBox" >
						<span class="ljw-span nameSpan">${p.patient_name }</span>
						<p class="ljw-span">
							<span>${p.patient_age }</span>岁
							<span class="dep-span">${p.departments_name }</span>
						</p>
					</div>
				</div>
				<div class="timeBox">
					<span>
						<fm:formatDate value="${p.hospital_time }" pattern="yyyy-MM-dd  hh:mm"/>
					</span>入院
					<span>${p.days }天</span>
				</div>
				<div class="stateBox">
					${p.hospital_state }
					<c:if test="${p.hospital_state }">
					
					</c:if>
				</div>
			</div>
		</c:forEach>
		</div>
	</div>
	<!-- 患者列表  End -->
	
	<!-- 医嘱管理  Start -->
	<div title="医嘱管理" >	
		<fieldset class="adviceFie" style="border: 1px solid darkseagreen;border-radius: 5px;width: fit-content;margin: 0 auto;">
			<legend>医嘱管理</legend>
			<div style="padding: 5px;background: #dee;">
				<input id="hidText2" class="easyui-searchbox" data-options="prompt:'住院号/姓名查询'" 
		    	style="width:160px;height:28px;padding-left:5px;">
		    	<div style="display: inline-block ;padding: 5px 20px;margin: 0 10px;">
				</div>
				<a class="easyui-linkbutton" id="endBtn" iconCls="icon-remove" style="padding:0 5px;margin-left: 10px;">停 嘱</a>	
				<a class="easyui-linkbutton" id="adDetailsBtn" iconCls="icon-detail" style="padding:0 5px;margin-left: 10px;">详 情</a>	
			</div>
			<table id="adTable" class="easyui-datagrid" style="height:360px;width: 1000px" 
	        		data-options="singleSelect:true">   
			   
			</table> 
			<!-- 详情弹框  Start -->
			<div class="easyui-window adDetailWin" title="医嘱详情" style="width:580px;user-select:none;"
				data-options="modal:true,collapsible:false,minimizable:false,
				maximizable:false,closed:true,draggable:false,shadow:true,resizable:false" style="padding:20px 40px">
				<table id="adDetailTable" class="easyui-datagrid" style="height:300px" >
				      
				</table> 
			</div>
			<!-- 详情弹框  End-->
		</fieldset>
	</div>
	<!-- 医嘱管理  End -->
	
	<!-- 手术安排  Start -->
	<div title="手术安排">	
		<form action="" method="post" id="opsForm">
			<div style="padding: 10px 5px;background: #dee;" id="opsBox">
				<select id="opsSear" class="easyui-combogrid" name="dept" data-options="prompt:'选择患者'" required ="required" style="width:100px;"></select>
				
				<select id="selectOps" class="easyui-combogrid" data-options="prompt:'选择手术'" required ="required" style="width:140px;"></select>
				
				<input id="startTime" class= "easyui-datetimebox" required ="required" showSeconds=false
						data-options="label:'开始时间：',labelAlign:'right',width:230,editable:false">
				 
				<input id="endTime" class="easyui-timespinner"  style="width:170px;" required ="required" 
        			required="required" min='08:00' data-options="label:'结束时间：',showSeconds:true" /> 
				
				<select id="setNurse" name="nurse_id" class="easyui-combobox" editable="false" panelHeight="auto" required ="required"
				 	data-options="label:'安排助手：',labelAlign:'right'" style="width:180px;cursor: pointer;">
				</select>
				
				<select id="setTheater" name="theater_id" class="easyui-combobox" required ="required" editable="false" panelHeight="auto"
				 	data-options="label:'手术室：',labelAlign:'right'" style="width:200px;cursor: pointer;">
				</select>
				
				<a id="okOps" class="easyui-linkbutton" style="padding:0 5px;">确认安排</a>
			</div>
		</form>
		<table id="ops2-Table" class="easyui-datagrid" style="height:400px" 
	        	data-options="singleSelect:true,pagination:true">
		  
		</table> 
	</div>
	<!-- 手术安排  End -->
</div>
</body>
</html>